<template>
  <div>
    <div>
      <el-card>
        <el-button-group>
          <el-button :class="{ 'is-plain': currentFceId !== 1 }" type="primary" size="mini"
            @click="handleChange(1)">待处理评审</el-button>
          <el-button :class="{ 'is-plain': currentFceId !== 2 }" type="primary" size="mini"
            @click="handleChange(2)">发起评审</el-button>
        </el-button-group>
      </el-card>
    </div>
    <div style="margin-top: 20px; height: 100%">
      <el-row :gutter="10" style="height: 100%">
        <el-col :span="17" style="height: 100%">
          <el-card style="height: 100%">
            <div slot="header">
              待处理评审
              <el-button size="small" type="text" style="float:right;text-decoration: underline"
                @click="getMore(1)">更多</el-button>
            </div>
            <hmi-table :table-data="pendingProcessing" :is-pagination-show="true" :table-height="'calc(100vh - 300px)'"
              :table-head="true" :total="pendingProcessingTotal" :current-page="queryForm.current"
              :page-size="queryForm.page" index-tyle="index" @handle-size-change="handleSizeChange"
              @handle-current-change="handleCurrentChange">
              <template slot="TableHead">
                <el-form ref="queryForm" :model="queryForm" :inline="true">
                  <el-form-item label="顾客名称" prop="customerName">
                      <el-select
                        v-model="queryForm.customerName"
                        filterable
                        placeholder="请输入顾客名称"
                        allow-create
                        default-first-option
                        clearable
                        style="width: 6vw"
                      >
                        <el-option
                          v-for="item in customerList"
                          :key="item.id"
                          :label="item.customerName"
                          :value="item.customerName"
                        >
                        </el-option>
                      </el-select>
                  </el-form-item>
                  <el-form-item label="钢种" prop="steelGradeId">
                    <el-select v-model="queryForm.steelGradeId" filterable
                    allow-create
                    default-first-option placeholder="请选择钢种" style="width: 6vw" clearable>
                      <el-option v-for="item in steelGradeList" :key="item.id" :value="item.steelGradeName"
                        :label="item.steelGradeName" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="待处理事项" prop="itemId">
                    <el-select v-model="queryForm.itemId" placeholder="请选择待处理事项" style="width: 6vw" filterable
                    allow-create
                    default-first-option clearable>
                      <el-option v-for="item in waitThings" :key="item" :value="item" :label="item" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="钢类" prop="steelTypeId">
                    <el-select v-model="queryForm.steelTypeId" placeholder="请选择钢类" style="width: 6vw" filterable
                    allow-create
                    default-first-option clearable>
                      <el-option v-for="item in steelTypes" :key="item.id" :value="item.steelTypeName" :label="item.steelTypeName" />
                    </el-select>
                  </el-form-item>
                  <el-form-item label="编号" prop="code">
                    <el-input v-model="queryForm.code" size="mini" placeholder="请输入" clearable
                      style="width: 6vw"></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-button size="mini" type="primary" @click="getPendingProcessing()">查询</el-button>
                    <el-button size="mini" type="success"
                      @click="() => { $refs.queryForm.resetFields(); handleCurrentChange(1) }">重置</el-button>
                  </el-form-item>
                </el-form>
              </template>
              <template slot="TableBody">
                <el-table-column label="序号" type="index" align="center" width="70"></el-table-column>
                <el-table-column label="编号" align="center" prop="code"></el-table-column>
                <el-table-column label="待处理事项" align="center" prop="itemName" width="110">
                  <template slot-scope="scope">
                    {{ scope.row.itemName }}
                  </template>
                </el-table-column>
                <el-table-column label="顾客名称" align="center" prop="customerName" width="200"></el-table-column>
                <el-table-column label="顾客联系方式" align="center" width="160" prop="customerPhone"></el-table-column>
                <el-table-column label="钢类" align="center" prop="steelTypeName"></el-table-column>
                <el-table-column label="钢种" align="center" prop="steelGradeName"></el-table-column>
                <el-table-column label="规格" align="center" prop="specification" width="150"></el-table-column>
                <el-table-column label="数量" align="center" prop="steelNumber"></el-table-column>
                <el-table-column label="交货状态" align="center" prop="deliveryStatus" width="100"></el-table-column>
                <el-table-column label="加工用途" align="center" prop="processingPurpose" width="120"></el-table-column>
                <el-table-column label="操作" align="center">
                  <template slot-scope="scoped">
                    <el-button type="text" size="mini" @click="handle(scoped.row)">处理</el-button>
                  </template>
                </el-table-column>
              </template>
            </hmi-table>

          </el-card>
        </el-col>
        <el-col :span="7">
          <el-card style="height: 45vh">
            <div slot="header">
              已发送评审
              <el-button size="small" type="text" style="float:right;text-decoration: underline"
                @click="getMore(2)">更多</el-button>
            </div>
            <hmi-table :table-data="hasBeenSent" :is-pagination-show="true" :table-height="'calc(45vh - 105px)'"
              :table-head="true" :total="hasBeenSentTotal" :current-page="hasBeenSentForm.current"
              :page-size="hasBeenSentForm.page" index-tyle="index" @handle-size-change="hasBeenSentHandleSizeChange"
              @handle-current-change="hasBeenSentHandleCurrentChange">
              <template slot="TableBody">
                <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
                <el-table-column label="当前流程" align="center" prop="statusName" width="120">
                  <template slot-scope="scope">
                    {{ scope.row.statusName }}
                  </template>
                </el-table-column>
                <el-table-column label="顾客名称" align="center" prop="customerName" show-overflow-tooltip></el-table-column>
                <el-table-column label="钢种" align="center" prop="steelGradeName" width="100" show-overflow-tooltip></el-table-column>
                <el-table-column label="详情" align="center" width="50">
                  <template slot-scope="scope">
                    <el-button type="text" size="mini" @click="hanldeDetail(scope.row)">查看</el-button>
                  </template>
                </el-table-column>
              </template>
            </hmi-table>
          </el-card>
        </el-col>
        <el-col :span="7" style=" margin-top: 20px">
          <el-card style="height: 35vh">
            <div slot="header">
              历史评审
              <el-button size="small" type="text" style="float:right;text-decoration: underline"
                @click="getMore(3)">更多</el-button>
            </div>
            <hmi-table :table-data="historyData" :is-pagination-show="true" :table-height="'calc(35vh - 105px)'"
              :table-head="true" :total="historyDataTatol" :current-page="historyDataForm.current"
              :page-size="historyDataForm.page" index-tyle="index" @handle-size-change="historyDataHandleSizeChange"
              @handle-current-change="historyDataHandleCurrentChange">
              <template slot="TableBody">
                <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
                <el-table-column label="钢种" align="center" prop="steelGradeName" width="75"  show-overflow-tooltip></el-table-column>
                <el-table-column label="顾客名称" align="center" prop="customerName" show-overflow-tooltip></el-table-column>
                <el-table-column label="钢类" align="center" prop="steelTypeName" width="75"></el-table-column>
                <el-table-column label="存档日期" align="center" prop="submitTime">
                  <template slot-scope="scope">
                    <span>{{ formatterTime(scope.row.submitTime) }}</span>
                  </template></el-table-column>
                <el-table-column label="详情" align="center" width="50">
                  <template slot-scope="scope">
                    <el-button type="text" size="mini" @click="handleFile(scope.row)">查看</el-button>
                  </template>
                </el-table-column>
              </template>
            </hmi-table>
          </el-card>
        </el-col>
      </el-row>
    </div>
    <el-dialog :visible.sync="dialogVisible" :close-on-click-modal="false" title="查看"  width="80%" >
      <iframe
        :src="fileSrc"
        width="100%"
        height="100%"
        type="application/x-google-chrome-pdf"
      ></iframe>
    </el-dialog>
  </div>
</template>

<script>
import HmiTable from "@/components/HmiTable.vue";
import {
  GET_SALE_PENDREVIEW,
  GET_SALE_SENTREVIEW,
  GET_SALE_HISTORICALREVIEW,
  GET_STEELGRADELIST,
  GET_STEELTYPELIST,
  GET_CUSTOMERNAMELIST,
  GET_FILE_DOWNLOAD
} from "@/lib/Api.js";
import { post } from "@/lib/Util.js";
import { timeChange } from "@/lib/FormatTime";
export default {
  components: {
    HmiTable
  },
  data() {
    return {
      currentFceId: 1,
      queryForm: {
        code: "",
        current: 1,
        customerName: "",
        itemId: "",
        page: 5,
        standardId: "",
        steelGradeId: "",
        steelTypeId: ""
      },
      hasBeenSentForm: {
        page: 5,
        current: 1
      },
      historyDataForm: {
        page: 5,
        current: 1
      },
      waitThings: ["待规范信息", "待核定外委", "待提交", "待接单复评"],
      steelTypes: [],
      steelGradeList: [],
      pendingProcessing: [],
      hasBeenSent: [],
      historyData: [],
      pendingProcessingTotal: 0,
      hasBeenSentTotal: 0,
      historyDataTatol: 0,
      customerList: [],
      dialogVisible: false,
      fileSrc: ""
    };
  },
  mounted() {
    this.getPendingProcessing();
    this.gethasBeenSent();
    this.getHistoryData();
    this.getSteelGradeName();
    this.getsteelTypeNames(); // 获取钢类
    this.getCustomerNames(); // 获取顾客
  },
  methods: {
    formatterTime(time) {
      if (time !== "" && time !== undefined) {
        return timeChange(time);
      } else {
        return "";
      }
    },
    getSteelGradeName() {
      const requestData = {
        steelGradeName: ""
      };
      post(GET_STEELGRADELIST, requestData)
        .then(resp => {
          this.steelGradeList = resp.data;
        })
        .catch(error => {
          console.log(error);
        });
    },
    //获取待处理评审
    getPendingProcessing() {
      post(GET_SALE_PENDREVIEW, this.queryForm).then(resp => {
        const { total, rows } = resp;
        this.pendingProcessingTotal = total;
        this.pendingProcessing = rows;
      });
    },
    //获取待处理评审
    gethasBeenSent() {
      post(GET_SALE_SENTREVIEW, this.hasBeenSentForm).then(resp => {
        const { total, rows } = resp;
        console.log(total, rows);
        this.hasBeenSentTotal = total;
        this.hasBeenSent = rows;
      });
    },
    //获取历史评审
    getHistoryData() {
      post(GET_SALE_HISTORICALREVIEW, this.historyDataForm).then(resp => {
        const { total, rows } = resp;
        console.log(total, rows);
        this.historyDataTatol = total;
        this.historyData = rows;
      });
    },
    handleCurrentChange(current) {
      this.queryForm.current = current;
      this.getPendingProcessing();
    },
    handleSizeChange(page) {
      this.queryForm.page = page;
      this.handleCurrentChange(1);
    },
    hasBeenSentHandleCurrentChange(current) {
      this.hasBeenSentForm.current = current;
      this.gethasBeenSent();
    },
    hasBeenSentHandleSizeChange(page) {
      this.hasBeenSentForm.page = page;
      this.hasBeenSentHandleCurrentChange(1);
    },
    historyDataHandleCurrentChange(current) {
      this.historyDataForm.current = current;
      this.getHistoryData();
    },
    historyDataHandleSizeChange(page) {
      this.historyDataForm.page = page;
      this.historyDataHandleCurrentChange(1);
    },
    handle(row) {
      this.$router.push({
        name: "pendOrder",
        params: {
          id: row.id
        }
      });
    },
    hanldeDetail(row) {
      this.$router.push({
        name: "sale-orderDetails",
        params: { id: row.id }
      });
    },
    handleChange(fceId) {
      this.currentFceId = fceId;
      if (this.currentFceId == 2) {
        this.$router.push({
          path: "/sale/reviews"
        });
      }
    },
    getMore(val) {
      if (val === 1) {
        this.$router.push({
          path: "/sale/toBehandle"
        });
      } else if (val === 2) {
        this.$router.push({
          path: "/sale/toBeSent"
        });
      } else if (val === 3) {
        this.$router.push({
          path: "/sale/history"
        });
      }
    },
    async handleFile(row) {
      var res = await post("", [], {
        responseType: "blob"
      });
      console.log(res, "res");
    },
    // 获取钢类
    getsteelTypeNames() {
      post(GET_STEELTYPELIST, { steelTypeName: "" }).then(resp => {
        this.steelTypes = resp.data;
      });
    },
    // 获取顾客
    getCustomerNames() {
      post(GET_CUSTOMERNAMELIST, { customerName: "" }).then(resp => {
        this.customerList = resp.data;
      });
    }
  }
};
</script>

<style scoped>
</style>
